﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MyRecipeBook.Classes.Misc
{
    public static class Tags
    {
        public static string OpenTag(string tag, int indentLevel)
        {
            var s = "";
            for (var i = 0; i < indentLevel; i++)
                s += "\t";

            return (s + string.Format("<{0}>", tag));
        }

        public static string OpenTag(string tag, List<Tag> data, int indentLevel)
        {
            var s = "";
            for (var i = 0; i < indentLevel; i++)
                s += "\t";

            var s2 = "";
            foreach (var t in data)
                s2 += string.Format(" {0}", t);

            return (s + string.Format("<{0}{1}>", tag, s2));
        }


        public static string OpenTag(string tag)
        {
            return (string.Format("<{0}>", tag));
        }

        public static string OpenTag(string tag, List<Tag> data)
        {
            var s2 = "";
            foreach (var t in data)
                s2 += string.Format(" {0}", t);

            return (string.Format("<{0}{1}>", tag, s2));
        }

        public static string CloseTag(string tag, int indentLevel)
        {
            var s = "";
            for (var i = 0; i < indentLevel; i++)
                s += "\t";

            return (s + string.Format("</{0}>", tag));
        }

        public static string CloseTag(string tag)
        {
            return (string.Format("</{0}>", tag));
        }

        public static string Tag(Tag tag, int indentLevel)
        {
            var s = "";
            for (var i = 0; i < indentLevel; i++)
                s += "\t";

            return (s + string.Format("<{0}>{1}</{0}>", tag.Name, tag.Data));
        }

        public static string Tag(Tag tag, List<Tag> data, int indentLevel)
        {
            var s = "";
            for (var i = 0; i < indentLevel; i++)
                s += "\t";

            var s2 = "";
            foreach (var t in data)
                s2 += string.Format(" {0}", t);

            return (s + string.Format("<{0}{2}>{1}</{0}>", tag.Name, tag.Data, s2));
        }
    }

    public class Tag
    {
        public string Name { get; set; }
        public string Data { get; set; }

        public override string ToString()
        {
            return string.Format(" {0}=\"{1}\"", Name, Data);
        }
    }
}
